package com.LeeCode;

import java.util.Arrays;

/**
 * 推多米诺
 */

public class Code838 {
    public static void main(String[] args) {
        String dominio = "RR.L";
        System.out.println(new Code838().pushDominoes(dominio));
    }

    public String pushDominoes(String dominoes) {
        char[] chars = ("L" + dominoes + "R").toCharArray();
        int pre = 0;
        for (int i = 1; i < chars.length; i++) {
            if (chars[i] == '.')
                continue;

            if (chars[i] == chars[pre]) {
                Arrays.fill(chars, pre + 1, i, chars[pre]);
            } else if (chars[i] == 'L') {
                Arrays.fill(chars, pre + 1, (pre + 1 + i) / 2, 'R');
                Arrays.fill(chars, (pre + i) / 2 + 1, i, 'L');
            }
            pre = i;
        }

        return new String(chars, 1, chars.length - 2);
    }
}
